#include <cstdint>
#include <iostream>
#include <istream>
#include <string>
using ll = int64_t;
#define printf
const ll maxn = 1e5+7;
ll n,m,ans;
struct S{
    int op;
    std::string s;
}s[maxn];

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin>>n>>m;
    for(ll i=0;i<n;i++){
        std::cin>>s[i].op>>s[i].s;
        s[i].op=s[i].op==0?1:-1;
    }
    for(ll i=1;i<=m;i++){
        ll a,b;
        std::cin>>a>>b;
        a=a==0?-1:1;
        ans=(ans+a*s[(ans%n+n)%n].op*b)%n;
        printf("ans=%lld\n",ans);
    }
    std::cout<<s[(ans%n+n)%n].s<<"\n";
}